package com.dkcrow.transaction.anno.springconf;

import javax.annotation.Resource;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.transaction.interceptor.TransactionInterceptor;

@Aspect
public class TransactionAdvisor {
	@Resource(name="imAdvice") TransactionInterceptor imAdvice;
	@Resource(name="idPoolAdvice") TransactionInterceptor idPoolAdvice;
	
	@Pointcut("@annotation(jwork.im.transaction.anno.IMTransaction) && execution(* *(..))")
	public void imDatabase() {
	}
	
	@Pointcut("@annotation(jwork.im.transaction.anno.IDPoolTransaction) && execution(* *(..))")
	public void idPoolDatabase() {
	}
	
	@Around("imDatabase()")
	public Object imDatabaseAround(ProceedingJoinPoint pjp) throws Throwable {
		MyMethodInvocation myMethodInvocation = MyMethodInvocation.newInstance(pjp);
		return imAdvice.invoke(myMethodInvocation);
	}
	
	@Around("idPoolDatabase()")
	public Object idPoolDatabaseAround(ProceedingJoinPoint pjp) throws Throwable {
		MyMethodInvocation myMethodInvocation = MyMethodInvocation.newInstance(pjp);
		return idPoolAdvice.invoke(myMethodInvocation);
	}
}